# === Base Stage ==================================================================================

FROM python:3.10-slim AS base

ARG PYANSYS_PRIVATE_PYPI_PAT

RUN apt update && apt install curl libx11-6 libglu1-mesa-dev libxrender1 libgl1-mesa-glx xvfb iputils-ping -y
RUN pip install --upgrade pip && pip install poetry==1.8.3
RUN poetry config http-basic.solutions-private-pypi PAT $PYANSYS_PRIVATE_PYPI_PAT

WORKDIR /app

COPY ../../pyproject.toml ../../poetry.lock /app/
COPY README.md /app/

RUN mkdir -p /app/src/ansys/solutions/{{ cookiecutter.__solution_name }}
RUN touch /app/src/ansys/solutions/{{ cookiecutter.__solution_name }}/__init__.py

RUN poetry install

RUN rm -rf /root/.cache/pip/* /dist /var/lib/apt/lists/*

# === API Stage ===================================================================================

FROM base AS solution_api

COPY ../../src/ansys/solutions/{{ cookiecutter.__solution_name }} /app/src/ansys/solutions/{{ cookiecutter.__solution_name }}

ENTRYPOINT poetry run python -m uvicorn ansys.saf.glow.api:app --host $GLOW_API_HOST --port $GLOW_API_PORT --root-path /api

# === UI Stage ====================================================================================

FROM base AS solution_ui

RUN poetry install --only ui

COPY ../../src/ansys/solutions/{{ cookiecutter.__solution_name }} /app/src/ansys/solutions/{{ cookiecutter.__solution_name }}

ENTRYPOINT ["poetry", "run", "python", "-m", "ansys.saf.glow.cli", "ui"]